using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GenerateRandom:MonoBehaviour, IGenerationComponent {

	[SerializeField] float[] weights;

	private void Start() {
		OnGeneration();
	}

	public void OnGeneration() {

		int chosenIndex = Utility.RandomFromWeights(weights);

		if(chosenIndex<0||transform.childCount<=chosenIndex) {
			Destroy(gameObject);
			return;
		}
		Transform t = transform.GetChild(chosenIndex);
		t.parent=transform.parent;
		t.GetComponent<IGenerationComponent>()?.OnGeneration();
		Destroy(gameObject);

	}
}
